package com.example.myapplication.HomeRecyclerViewFragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.HomeRecyclerViewAdapter.JingPinBanJiAdapter;
import com.example.myapplication.HomeRecyclerViewFragment.HomeRecyclerViewBean.JingPinBanJiBean;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

public class JingPinBanJi extends Fragment {
    RecyclerView recyclerView;
    List<JingPinBanJiBean> list=new ArrayList<>();
    JingPinBanJiAdapter jingPinBanJiAdapter;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_jipinbanji,container,false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        recyclerView=view.findViewById(R.id.JingPinBanJi_RL);
        list.add(new JingPinBanJiBean(R.mipmap.homezhanjian055,"055型导弹驱逐舰"));
        list.add(new JingPinBanJiBean(R.mipmap.homezhanjian052d,"052D型导弹驱逐舰"));
        list.add(new JingPinBanJiBean(R.mipmap.homezhanjiandadi,"彼得大帝号核动力巡洋舰"));
        list.add(new JingPinBanJiBean(R.mipmap.homezhanjianboke,"阿利·伯克级驱逐舰"));
        list.add(new JingPinBanJiBean(R.mipmap.homezhanjian45,"45型驱逐舰"));
        //定了布局管理
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this.getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        //设置管理布局
        recyclerView.setLayoutManager(linearLayoutManager);
        jingPinBanJiAdapter=new JingPinBanJiAdapter(list);
        recyclerView.setAdapter(jingPinBanJiAdapter);
    }
}
